package com.zx.sa.controller;

import com.zx.sa.router.ModelRouter;
import com.zx.sa.router.TaskType;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.ChatClient.ChatClientRequestSpec;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin(origins = "*")
@RequestMapping("/chat")
public class ChatController {

    @Autowired
    private ModelRouter modelRouter;

    @GetMapping("/index")
    public String index(Model model) {
        model.addAttribute("taskTypes", TaskType.values());
        return "chat";
    }

    @RequestMapping("/chat")
    @ResponseBody
    public String chat(@RequestParam(value = "input", defaultValue = "你好，你是谁") String input,
            @RequestParam(value = "taskType", defaultValue = "auto") String taskType) {
        return this.modelRouter.chat(input, taskType);
    }

} 